﻿@model IEnumerable<Microsoft.Online.Demos.Aadexpense.ServiceReference1.User>

@{
    ViewBag.Title = "Users";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Users</h2>

<script src="@Url.Content("https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("https://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

    <table>
        <tr>
       @using (Ajax.BeginForm("Search", "Admin", new AjaxOptions()
                                                                {
                                                                    HttpMethod = "GET",
                                                                    InsertionMode =  InsertionMode.Replace,
                                                                    UpdateTargetId = "searchResults"
                                                                }))
       {
           <input type="text" name="q" data-autocomplete="@Url.Action("QuickSearch", "Admin")" />
           <input type="submit" value="Search"/>
       }
        </tr>
    </table>
<table>
    <tr>
        @if (ViewBag.HasPrevPage != null && ViewBag.HasPrevPage == true)
        {
            <td>@Html.ActionLink("Prev", "AddUsers", new { type = "prev" })</td>
        }
        @if (ViewBag.HasNextPage != null && ViewBag.HasNextPage == true)
        {
            <td>@Html.ActionLink("Next", "AddUsers", new { type = "next" })</td>
        }
        @if (ViewBag.FilteredUserView != null && ViewBag.FilteredUserView == true)
        { 
          }

    </tr>

</table>
<br />
<table id="searchResults">
    <tr>
        <th>
            DisplayName
        </th>        
        <th>
            UserPrincipalName
        </th>
        <th>
            Add to application
        </th>
    </tr>

@if (Model != null)
{
    foreach (var item in Model)
    {
    <tr>
        <td>
            @Html.ActionLink(item.DisplayName, "UserDetails", new { id = item.ObjectId }, null)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.UserPrincipalName)
        </td>
        <td>
            @Html.ActionLink("Add", "AddUser", "Admin", new { employeeId = item.ObjectId }, null)
        </td>
    </tr>
    }
}
</table>

<p>    
    @Html.ActionLink("Back to Views", "Index")
</p>
